package moon.core;

import java.io.Serializable;

import moon.traverse.Visitor;

import org.apache.log4j.Logger;

/**
 * Root of the MOON hierarchy.
 * 
 * @author <a href="mailto:rmartico@ubu.es">Ra&uacute;l Marticorena</a>
 * @since JavaMoon-2.0
 */
@SuppressWarnings("serial")
public abstract class ObjectMoon implements Serializable{
	
	/**
	 * Logger.
	 */
	public static Logger logger = Logger.getLogger(ObjectMoon.class);
	
	static{
		logger.setLevel(null); // allows the inheritance of the logger among loggers		
	}
	
	/**
	 * Initial unique number.
	 */
	private static int genId = 0;
	
	/**
	 * Identify Number.
	 */
	private int id;
	
	/**
	 * Row in the file source when this object appears.
	 */
	private long line;
	
	/**
	 * Column in the file source when this object appears.
	 */
	private long column;
	
	/**
	 * Constructor. Generates a new number for each
	 * new object moon.
	 */
	public ObjectMoon(){
		id = genId;
		genId++;
	}
	
	/**
	 * Constructor. Generates a new number for each
	 * new object moon.
	 * 
	 * @param line line
	 * @param column column 
	 */
	public ObjectMoon(int line, int column){
		id = genId;
		genId++;
		this.setLine(line);
		this.setColumn(column);
	}
	
	/**
	 * Gets the id number.
	 * 
	 * @return id
	 */
	public int getId() { return id; }
	
	/**
	 * Gets the line.
	 * 
	 * @return line
	 * @see #setLine
	 */
	public long getLine() { return line; }
	
	/**
	 * Gets the column.
	 * 
	 * @return column
	 * @see #setColumn
	 */
	public long getColumn() { return column; }
	
	/**
	 * Sets the line.
	 * 
	 * @param line line
	 * @see #getLine
	 */
	public void setLine(long line){
		this.line = line;
	}
	
	/**
	 * Sets the column.
	 * 
	 * @param column column
	 * @see #getColumn
	 */
	public void setColumn(long column){
		this.column = column;
	}	
	
	/**
     * Method from Pattern Design Visitor.
     * By RMS.
     * 
     * @param visitor visitor
     */
    public void accept(Visitor visitor) {
    	// Hook method
    	visitor.visit(this);
    }
	
} // ObjectMoon
